Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Invoking object methods
In addition to attributes, some objects support methods. A method is an operation that performs a specific action related to an object. You can think of methods as being very much like the built-in functions the language supports. The methods are also identified by keywords that you use in 4GL syntax following an object reference, which can be the object name or handle followed by a colon, just as for attributes:
Methods typically take one or more arguments, defined in a comma-separated list in parentheses following the method name.
For example, in the next chapter you’ll learn how to view a text field as an editor, with multiple lines and scrollbars and so forth. There’s an editor method, called
READ-FILE, that you can use to open and read an operating system file into an editor, just as the Progress Procedure Editor does.READ-FILEtakes a single argument, the name of the file to read. So this sample syntax reads a file into an editor calledcEditor:
Methods always return a value, just as built-in functions do. Generally, that value is a
LOGICALindicating whether the operation succeeded or not (with aTRUEvalue indicating success). You can assign the return value to a variable or field in an assignment statement:
The initial letter
lindicates that this is a logical variable.You can also ignore the return value (as you can with any function) and simply treat the method reference as a statement of its own:
Some methods return more meaningful values that you would normally not ignore. Indeed, some methods exist solely to return a meaningful value. You can think of these methods as being similar to attributes. However, because an input parameter is required and attribute references cannot take parameters, you use a method instead to retrieve the return value. For example, the following code sample uses a Progress system-wide object called
FONT-TABLEto calculate the width of a button label in the current font. It then uses this value to calculate the required width of a frame that has five buttons. Because the button label must be passed in to the operation, the syntax must be defined as a method (in this case calledGET-TEXT-WIDTH-CHARS) rather than an attribute (which might have been calledTEXT-WIDTH-CHARS):
As you can see from this example, you can reference the method within an expression anywhere another value could appear.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |